package com.qa.controller.user;

import com.qa.dto.DeleteManyDTO;
import com.qa.dto.NoteAddDTO;
import com.qa.dto.NoteSelfQueryDTO;
import com.qa.dto.NoteUpdateDTO;
import com.qa.result.Result;
import com.qa.service.NoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户端笔记相关接口")
@RestController
@RequestMapping("/user/notes")
public class NoteController {

    @Autowired
    private NoteService noteService;

    @ApiOperation("根据问题id获取笔记")
    @GetMapping("/{questionId}")
    public Result getNotesByQuestionId(@PathVariable Long questionId) {
        return noteService.getNotesByQuestionId(questionId);
    }

    @ApiOperation("添加笔记")
    @PostMapping
    public Result addNote(@RequestBody NoteAddDTO noteAddDTO) {
        return noteService.addNote(noteAddDTO);
    }

    @ApiOperation("条件查询自己的笔记")
    @GetMapping("/condition/my")
    public Result getNotesByCondition(NoteSelfQueryDTO noteSelfQueryDTO) {
        return noteService.getNotesByCondition(noteSelfQueryDTO);
    }

    @ApiOperation("更新笔记")
    @PutMapping
    public Result updateNote(@RequestBody NoteUpdateDTO noteUpdateDTO) {
        return noteService.updateNote(noteUpdateDTO);
    }

    @ApiOperation("删除笔记")
    @DeleteMapping("/{noteId}")
    public Result updateNote(@PathVariable Long noteId) {
        return noteService.deleteNote(noteId);
    }

    @PostMapping("/delete/many")
    @ApiOperation(value = "批量删除笔记")
    public Result deleteQuestion(@RequestBody DeleteManyDTO deleteManyDTO) {
        return noteService.deleteNotes(deleteManyDTO.getIds());
    }
}
